<template>
	<view>
		<view class="container">
			<view class="activeDetail">
				<view class="activeDetail-title">
					<text class="article-title">{{detail.title}}</text>
				</view>
				
				<view style="display: flex;">
					<view class="activeDetail-info">
						<view class="team-tit">{{$t('app.other.publisher')}}：{{detail.userName}}</view>
						<view class="team-tit">{{$t('app.other.noticeType')}}：{{detail.publicItem | codeFormat(publicOptions)}}</view>
						<view class="team-tit">{{$t('app.other.isPublic')}}：{{detail.public0 | codeFormat(yesOrNoOptions)}}</view>
						<view class="team-tit">{{$t('app.other.effectiveTime')}}：{{detail.publicDate | dateFormat('yyyy-MM-dd')}} {{$t('baseCommon.other.to')}} {{detail.loseDate | dateFormat('yyyy-MM-dd')}}</view>
					</view>
					<view class="activeDetail-img" v-if="detail.picture">
						<image :src="$getImg(detail.picture, 'pic')"></image>
					</view>
				</view>
				
				<view class="article-line"></view>
				
				<rich-text :nodes="detail.content"></rich-text>
				
				<view class="article-line"></view>
				
				<view>
					<p>{{$t('common.field.attachFile')}}</p>
					<p><file-list :files="attachments"></file-list></p>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	import FileList from '@/components/business/attach-file/file-list.vue'
	import { getNoticeDetail } from '@/api/platform/common.js'
	import { getAttachment } from '@/api/base/file.js'
	import constants from '@/utils/constants.js'
	
	export default {
		components: {
			FileList
		},
		onLoad(params) {
			this.noticeId = params.noticeId
			this.loadData()
		},
		data() {
			return {
				noticeId: '',
				detail: {},
				attachmentIds: [],
				attachments: [],
				publicOptions: constants.publicOptions,
				yesOrNoOptions: constants.yesOrNoOptions
			}
		},
		methods: {
			loadData() {
				getNoticeDetail(this.noticeId).then(res => {
					this.detail = res.data
					if(res.data.fileAttach){
						res.data.fileAttach.split(",").forEach(item=>{
							this.attachmentIds.push(item)
						})
						this.getAttachment()
					}
				})
			},
			getAttachment() {
				getAttachment(this.attachmentIds).then(res=>{
					this.attachmentIds.forEach(item=>{
						let data = res.data[item]
						this.attachments.push({
							ext: data.ext,
							name: data.fileName,
							id: data.id,
							size: data.totalBytes
						})
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	.container {
		background-color: #fff;
	}
	
	.activeDetail {
		padding: 10px;
		display: flex;
		flex-direction: column;
		
		.activeDetail-title {
			display: flex;
			flex-direction: column;
			
			.article-title {
				font-size: 20px;
			}
			
			.article-date {
				margin-top: 10px;
				color: $app-font-color-subtitle;
			}
		}
		
		.activeDetail-info {
			display: flex; 
			flex-direction: column; 
			width: 75%;
			
			.team-tit {
				font-size: 13px; 
				color: #999; 
				margin-top: 5px;
			}
		}
		
		.activeDetail-img {
			width: 25%;
			
			image {
				height: 80px;
				width: 90px;
			}
		}
		
		.article-line {
			margin: 15px 0;
			height: 1px;
			width: 100%;
			background-color: #eeeeee;
		}
	}
</style>
